﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LearnThemselvesEffectively.Classes
{
    public class LearnCore : TranslationCore
    {
        public LearnCore(int StageNo)
        {
            rand = new Random();
            moPersistantLayer = new PersistantLayerXML();
            WordsInStage = moPersistantLayer.RetrieveAllTranslateItemsInStage(StageNo);
            foreach (var oItem in WordsInStage) WordsNotLearnedInStageID.Add(oItem.ID);
            msWarningMessage = "Do you really want to finish learn session?" + Environment.NewLine + Environment.NewLine + "You will be able leter finish thi course.";
        }

        #region Members and properties
        //TODO methods: checkTranslation, 
        public List<int> WordsNotLearnedInStageID;

        private static Random rand;
        private PersistantLayerXML moPersistantLayer;
        #endregion

        #region Public methods
        /// <summary>
        /// Check if learned word and if yes remove it ID from list
        /// </summary>
        /// <param name="inputedWord"></param>
        public void CheckIfLearned(string inputedWord)
        {
            if (CheckTranslation(inputedWord) == true)
            {
                if (CurrTranstationItem.CorrectTranslation == 3 && CurrTranstationItem.Mistranslation == 0)
                {
                    CurrTranstationItem.TranslationPoints = 100;
                }
                else
                {
                    CurrTranstationItem.TranslationPoints += 25;
                }
                WordsNotLearnedInStageID.Remove(WordsNotLearnedInStageID.IndexOf(CurrentWordID));
            }
            else
            {
                CurrTranstationItem.TranslationPoints -= 25;
                if (CurrTranstationItem.TranslationPoints < 0) CurrTranstationItem.TranslationPoints = 0;
            }
        }

        /// <summary>
        /// Next word to learn
        /// </summary>
        public override void NextWord()
        {
            if (WordsNotLearnedInStageID.Count == 0)
            {
                GlobalSupportModele.SessionState = GlobalSupportModele.eSessionState.Finished;
                return;
            }
            CurrentWordID = WordsNotLearnedInStageID[rand.Next(WordsNotLearnedInStageID.Count)];
            //TODO save WordsDictionary.xml in persistant Layer
        }
        #endregion

        #region Private methods

        #endregion
    }
}
